﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace EasyFramework.Win32
{
    public class Kernel32Wrapper
    {
        /// <summary>
        /// 通过线程ID获取ProcessThread对象
        /// </summary>
        /// <param name="threadID">默认（0）为获取当前线程对象</param>
        /// <returns></returns>
        public static ProcessThread GetProcessThreadByID(Int32 threadID = 0)
        {
            ProcessThread pthred = null;
            if (threadID == 0)
                threadID = Kernel32.GetCurrentThreadId();

            foreach (ProcessThread proThread in Process.GetCurrentProcess().Threads)
            {
                if (proThread.Id == threadID)
                    pthred = proThread;
                else
                    pthred = Process.GetCurrentProcess().Threads[0];
            }
            return pthred;
        }
    }
}
